﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

using YLPublicService;

using YLPublicService.TransferModel;
namespace YLServiceCLient.YLAdminClient
{
    class AdminServiceClient : ClientBase<IAdminService>
    {
        private AdminServiceClient()
            : base()
        {
            loginSuccessGuid = Guid.Empty;
        }
        static AdminServiceClient client;
        static object sync = new object();
        public static AdminServiceClient GetServiceClient()
        {
            if (client == null)
            {
                lock (sync)
                {
                    client = new AdminServiceClient();
                }
            }
            return client;
        }
        public static void ResetServiceSetting()
        {
            client = null;
        }

        public Guid loginSuccessGuid;

        #region 封装服务提供的方法


        public bool AddAdminUser(string loginName, string pwd, string memo, bool isAdmin, Guid guid)
        {
            return Channel.AddAdminUser(loginName, pwd, memo, isAdmin, guid);
        }

        public bool ConbindAll(string serverUserLoginName, Guid guid)
        {
            return Channel.ConbindAll(serverUserLoginName, guid);
        }

        public bool AddUser(string loginName, string pwd, string userName, string memo, Guid guid)
        {
            return Channel.AddUser(loginName, pwd, userName, memo, guid);
        }

        public bool DeleteUser(string loginName, Guid guid)
        {
            return Channel.DeleteUser(loginName, guid);
        }

        public bool EnableUser(string loginName, Guid guid)
        {
            return Channel.EnableUser(loginName, guid);
        }

        public bool DisableUser(string loginName, Guid guid)
        {
            return Channel.DisableUser(loginName, guid);
        }

        public IEnumerable<User> GetUsers(Guid guid)
        {
            return Channel.GetUsers(guid);
        }

        public IEnumerable<WorkItem2ServerUser> GetWorkItems(string userLoginName, Guid guid)
        {
            return Channel.GetWorkItems(userLoginName, guid);
        }

        public IEnumerable<WorkItem2ServerUser> GetWaitingProcessWorkItems(string userLoginName, Guid guid)
        {
            return GetWaitingProcessWorkItems(userLoginName, guid);
        }

        public void DeleteWorkItems(string userLoginName, Guid guid)
        {
            Channel.DeleteWorkItems(userLoginName, guid);
        }

        public void DeleteWorkItem(string userLoginName, string boyName, string grilName, Guid guid)
        {
            Channel.DeleteWorkItem(userLoginName, boyName, grilName, guid);
        }

        public bool UpdateWorkItem(int workItemID, WorkItemStatus status)
        {
            return Channel.UpdateWorkItem(workItemID, status, loginSuccessGuid);
        }

        public void UpdateUserAccount(string userLoginName, decimal money, Guid guid)
        {
            Channel.UpdateUserAccount(userLoginName, money, guid);
        }

        public FtpServerInfo RequestFtpServerInfo()
        {
            return Channel.RequestFtpServerInfo(loginSuccessGuid);
        }

        public YLPublicService.TransferModel.TemplateItem[] GetDisableTemplates(Guid guid)
        {
            return Channel.GetDisableTemplates(guid);
        }

        public YLPublicService.TransferModel.Process GetTemplateProcessConfig(Guid guid, int templateID)
        {
            return Channel.GetTemplateProcessConfig(guid, templateID);
        }

        public Guid Login(string loginName, string pwd)
        {
            loginSuccessGuid = Channel.Login(loginName, pwd);
            return loginSuccessGuid;
        }

        public void LoginOut(Guid guid)
        {
            Channel.LoginOut(guid);
        }

        public YLPublicService.TransferModel.TemplateItem[] GetEnableTemplates()
        {
            return Channel.GetEnableTemplates(loginSuccessGuid);
        }

        public bool UpdateTemplate(TemplateItem t)
        {
            return Channel.UpdateTemplate(t, loginSuccessGuid);
        }
        public bool AddTemplate(TemplateItem t)
        {
            return Channel.AddTemplate(t, loginSuccessGuid);
        }
        public bool DeleteTemplate(int tID)
        {
            return Channel.DeleteTemplate(tID, loginSuccessGuid);
        }
        #endregion
    }
}
